<template>
  <div>
    <div class="top">
      <div class="left">星辰教务系统</div>
      <div class="right">
        <label v-if="user.StuId==null">欢迎您！{{user.WorkerName}}</label>
        <label v-else>欢迎您！{{user.StuName}}</label>
        <el-tooltip
          class="item"
          effect="dark"
          content="个人中心"
          placement="bottom"
          style="margin-left:20px"
        >
          <el-link type="primary">
            <i class="el-icon-user" @click="Info()"></i>
          </el-link>
        </el-tooltip>
        <el-tooltip
          class="item"
          effect="dark"
          content="修改密码"
          placement="bottom"
          style="margin-left:20px;margin-right:10px"
        >
          <el-link type="primary">
            <i class="fontFamily hhtxxiugaimima" @click="dialogFormVisible = true"></i>
          </el-link>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="退出登入" placement="bottom">
          <el-link type="primary" @click="loginout()">
            <span class="fontFamily hhtxtuichu"></span>
          </el-link>
        </el-tooltip>
      </div>
    </div>
    <el-dialog title="修改密码" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="用户名" :label-width="formLabelWidth">
          <el-input v-model="form.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="旧密码" :label-width="formLabelWidth">
          <el-input v-model="form.oldpwd" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="新密码" :label-width="formLabelWidth">
          <el-input v-model="form.newpwd" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="UpdatePasswprd()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogFormVisible:false,
      form:{
        username:"",
        oldpwd:"",
        newpwd:""
      },
      user: ""
    };
  },
  created() {
    this.user = JSON.parse(sessionStorage.getItem("user"));
  },
  mounted() {},
  methods: {
    UpdatePasswprd() {
      this.$axios({
        method: "put",
        url: this.$api.UpdatePasswprd,
        params: {
          oldPwd: this.form.oldpwd,
          newPwd: this.form.newpwd,
          userName: this.form.username
        }
      }).then(res => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            message: "修改密码成功",
            type: "success"
          });
          this.forgetpass = 1;
        } else {
          this.$message({
            message: "账号或密码错误",
            type: "error"
          });
        }
      });
      this.dialogFormVisible = false
    },
    Info() {
      this.$router.push("/studentInfo");
    },
    loginout() {
      this.$confirm("确定退出吗, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          sessionStorage.clear();
          this.$router.push("/");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "退出失败"
          });
        });
    }
  }
};
</script>

<style scoped>
.top {
  width: 100%;
  height: 50%;
  background-color: white;
  margin-bottom: 20px;
  line-height: 40px;
  display: flex;
  justify-content: space-between;
}
.top .left {
  padding-left: 20px;
}
.top .right {
  padding-right: 20px;
}
.top .right span {
  margin-left: 10px;
}
</style>



